package org.finesys.chat.core.base.embedding.filter.logical;

import org.finesys.chat.core.base.embedding.filter.Filter;
import org.finesys.common.core.util.ValidationUtil;

import java.util.Objects;

public class AndFilter implements Filter {

    private final Filter left;
    private final Filter right;

    public AndFilter(Filter left, Filter right) {
        this.left = ValidationUtil.ensureNotNull(left, "left");
        this.right = ValidationUtil.ensureNotNull(right, "right");
    }

    public Filter getLeft() {
        return left;
    }

    public Filter getRight() {
        return right;
    }

    @Override
    public boolean test(Object object) {
        return this.getLeft().test(object) && this.getRight().test(object);
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;
        AndFilter andFilter = (AndFilter) object;
        return Objects.equals(left, andFilter.left) && Objects.equals(right, andFilter.right);
    }

    @Override
    public int hashCode() {
        return Objects.hash(left, right);
    }
}
